package com.ctcc.controller;

import com.ctcc.entity.count.DbZhiDuMemory;
import com.ctcc.entity.count.DbZhuBeiMemory;
import com.ctcc.entity.count.Memory;
import com.ctcc.serviceImpl.CountImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Peanut on 2018/5/29.
 */
@Controller
@RequestMapping(value = "/admin")
public class AdminController {
    @Autowired  CountImpl countImpl;
    @GetMapping(value = "/login")
    public  String login(){
        return "admin/login";
    }

    @PostMapping(value = "/check_login")
    public  String checkLogin(@RequestParam String username){
        System.out.println(username);
        return "redirect:/admin/index";
    }

    @RequestMapping(value = "/index")
    public  String index(){
        return "admin/index";
    }
    @RequestMapping(value = "/yunzhuji")
    public  String yunZhuJiList(ModelMap model){
        model.put("yunZhuJiLists", countImpl.getAllYunZhuJiInfo());
        model.put("item","云主机");
        return "admin/yunzhuji-list";
    }
    @RequestMapping(value = "/edit/{id}")
    public  String toEditYunZhuJi(ModelMap model,@PathVariable Long id){
        model.put("yunZhuJi", countImpl.getYunZhuJiInfo(id));
        return "admin/yunzhuji-form";
    }

    @RequestMapping(value = "/save")
    public  String saveYunZhuJi(@Validated Memory memory){
        countImpl.saveYunZhuJi(memory);
        return "redirect:/admin/index";
    }
    @RequestMapping(value = "/guanxixinzb")
    public  String guanxixingDbListOfZbList(Map<String,Object> map){
        map.put("GXXOfZbLists",countImpl.getAllGuanxixingOfZb());
        map.put("item","关系型数据库-主备实例");
        return "admin/guanxinxingofzb-list";
    }

    @RequestMapping(value = "/edit/guanxixingzb/{id}/")
    public  String toEditGuanXiXingZb(ModelMap model,@PathVariable Long id){
        model.put("GXXOfZb", countImpl.getGuanXiXingZbInfo(id));
        return "admin/guanxinxingofzb-form";
    }

    @RequestMapping(value = "/save/guanxixingzb")
    public  String saveGuanXiXingZb(@Validated DbZhuBeiMemory dbZhuBeiMemory){
        countImpl.saveGuanXiXingZb(dbZhuBeiMemory);
        return "redirect:/admin/index";
    }
    @RequestMapping(value = "/save/guanxixingzd")
    public  String saveGuanXiXingZd(@Validated DbZhiDuMemory  dbZhiDuMemory){
        countImpl.saveGuanXiXingZd(dbZhiDuMemory);
        return "redirect:/admin/index";
    }




    @RequestMapping(value = "/edit/guanxixingzd/{id}/")
    public  String toEditGuanXiXingZd(ModelMap model,@PathVariable Long id){
        model.put("GXXOfZd", countImpl.getGuanXiXingZdInfo(id));
        return "admin/guanxinxingofzd-form";
    }




    @RequestMapping(value = "/guanxixinzd")
    public  String guanxixingDbListOfZdList(Map<String,Object> map){
        map.put("GXXOfZdLists",countImpl.getAllGuanxixingOfZd());
        map.put("item","关系型数据库-只读实例");
        return "admin/guanxinxingofzd-list";
    }

}
